﻿using FluentScheduler;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiYiTong.Rocket.Helper;

namespace YiYiTong.Rocket.ProcessConsole
{
    public class BaseJob : IJob
    {
        private readonly object _lock = new object();

        private bool _shuttingDown;

        public virtual void Execute()
        {
            lock (_lock)
            {
                if (_shuttingDown)
                    return;
                try
                {
                    DoAction();
                }
                catch (Exception ex)
                {
                    LogHelper.Fatal(ex.GetExcetionMessage());
                }
            }
        }

        /// <summary>
        /// 定时执行
        /// </summary>
        public virtual void DoAction()
        {

        }

        public virtual void Stop(bool immediate)
        {
            lock (_lock)
            {
                _shuttingDown = true;
            }
            //HostingEnvironment.UnregisterObject(this);
        }
    }
}
